import time
import datetime
import json
from flask import (
    Blueprint, flash, g, redirect, render_template, request, url_for, send_from_directory, current_app, jsonify
)
from werkzeug.utils import secure_filename
from garden import db
from garden.models import Topic,TopicReply
from garden.auth import login_required

bp = Blueprint('discovery', __name__)

@bp.route('/discovery')
def discovery():
	return render_template('discovery/home.html')

@bp.route('/pubNotice', methods=('GET', 'POST'))
@login_required
def pub_notice():
	if request.method == 'POST':
		title = request.form['title']
		content = request.form['content']

		if title and content :
			topic = Topic(title=title,content=content,category='01',tags=None,publisher=g.user.id,pub_time=datetime.datetime.now(),cmnt_id=1001)
			db.session.add(topic)
			db.session.commit()
		return render_template('topic/msg.html')

	return render_template('discovery/pubnotice.html')